import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDUnit {
	/**ID*/
	id,
	/**名称*/
	name,
	/**描述*/
	desc,
	/**模型*/
	model,
	/**怪物属性类型1物理2火焰3冰冻4雷电*/
	petType,
	/**普攻*/
	nomarl_skill,
	/**主动_1*/
	activeSkill,
	/**被动_1*/
	passiveSkill,
	/**动画文件1*/
	animation_1,
	/**动画文件2*/
	animation_2,
	/**动画文件3*/
	animation_3,
	/**头像*/
	icon,
	/**图鉴id*/
	handBookid,
	/**血条位置x|y，单位/像素（不填表示按原本方式）*/
	hpPlace,

	/**枚举数量*/
	EnumCount
}



export class CDUnit{
	/**ID*/
	public id: number;
	/**名称*/
	public name: number;
	/**描述*/
	public desc: number;
	/**模型*/
	public model: string;
	/**怪物属性类型1物理2火焰3冰冻4雷电*/
	public petType: number;
	/**普攻*/
	public nomarl_skill: number;
	/**主动_1*/
	public activeSkill: number[];
	/**被动_1*/
	public passiveSkill: number[];
	/**动画文件1*/
	public animation_1: string;
	/**动画文件2*/
	public animation_2: string;
	/**动画文件3*/
	public animation_3: string;
	/**头像*/
	public icon: string;
	/**图鉴id*/
	public handBookid: string;
	/**血条位置x|y，单位/像素（不填表示按原本方式）*/
	public hpPlace: number[];


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDUnit.id: return this.id;
			case E_CDUnit.name: return this.name;
			case E_CDUnit.desc: return this.desc;
			case E_CDUnit.model: return this.model;
			case E_CDUnit.petType: return this.petType;
			case E_CDUnit.nomarl_skill: return this.nomarl_skill;
			case E_CDUnit.activeSkill: return this.activeSkill;
			case E_CDUnit.passiveSkill: return this.passiveSkill;
			case E_CDUnit.animation_1: return this.animation_1;
			case E_CDUnit.animation_2: return this.animation_2;
			case E_CDUnit.animation_3: return this.animation_3;
			case E_CDUnit.icon: return this.icon;
			case E_CDUnit.handBookid: return this.handBookid;
			case E_CDUnit.hpPlace: return this.hpPlace;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDUnit.id: this.id = v; break;
			case E_CDUnit.name: this.name = v; break;
			case E_CDUnit.desc: this.desc = v; break;
			case E_CDUnit.model: this.model = v; break;
			case E_CDUnit.petType: this.petType = v; break;
			case E_CDUnit.nomarl_skill: this.nomarl_skill = v; break;
			case E_CDUnit.activeSkill: this.activeSkill = v; break;
			case E_CDUnit.passiveSkill: this.passiveSkill = v; break;
			case E_CDUnit.animation_1: this.animation_1 = v; break;
			case E_CDUnit.animation_2: this.animation_2 = v; break;
			case E_CDUnit.animation_3: this.animation_3 = v; break;
			case E_CDUnit.icon: this.icon = v; break;
			case E_CDUnit.handBookid: this.handBookid = v; break;
			case E_CDUnit.hpPlace: this.hpPlace = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDUnit> = new HashMap<number, CDUnit>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDUnit[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDUnit();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].model = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].petType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].nomarl_skill = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].activeSkill = [];
			const attrArray = list[i].activeSkill;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].passiveSkill = [];
			const attrArray = list[i].passiveSkill;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].animation_1 = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].animation_2 = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].animation_3 = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].handBookid = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].hpPlace = [];
			const attrArray = list[i].hpPlace;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDUnit{
		return this.datas ? this.datas.get(id) : null;
	}
}
